<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加后台人员列表</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
</head>
<style>
    layui-table-cell{
        height: inherit;
        line-height: 20px;
    }
    .l{
        float: left;
    }
    .r{
        float: right;
    }
</style>
<body style="background-color: #F1F3F4">
<div style="margin-left: 20px;width: 93%;height: 50px;padding-top: 10px;background-color: #F1F1F1">
    <div>
        <div style="height: 30px; width: 5px;background-color:#009688 " class="l"></div>
        <h3 class="l" style="margin-top: 5px;margin-left: 5px">添加管理人员</h3>
        <div class="r" style="margin-right: 20px">
            <button type="button" class="layui-btn" onclick="refresh()">刷新</button>
            <button type="button" class="layui-btn" onclick="backOff()">返回</button>
        </div>
    </div>
</div>

<form class="layui-form">
    <div class="layui-row">
        <div class="layui-col-md3">
            <div style="height: 5px;width: 5px;"></div>
        </div>
        <div class="layui-col-md4">
            <div style="margin-left: 230px;margin-bottom: 10px">
                <img src="/images/moren.jpg"  id="headPortrait" style="width:100px; height:100px; border-radius:50%; border: #0B61A4 1px solid">
                <br/>
                <br/>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-inline">
                    <input type="text" name="trueName" class="layui-input" placeholder="输入姓名" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别：</label>
                <div class="layui-input-inline">
                    <input type="radio" name="sex" value="男" title="男">
                    <input type="radio" name="sex" value="女" title="女" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号码：</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" class="layui-input" placeholder="输入手机号" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">身份证：</label>
                <div class="layui-input-inline">
                    <input type="text" name="idCard" class="layui-input" placeholder="输入证件号" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">出生日期：</label>
                <div class="layui-input-inline">
                    <input type="text" name="birthDate" id="date1" class="layui-input" placeholder="输入出生日期" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱：</label>
                <div class="layui-input-inline">
                    <input type="text" name="email" class="layui-input" placeholder="输入邮箱" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">个性签名：</label>
                <div class="layui-input-inline">
                    <textarea class="layui-textarea" name="freestyle" placeholder="输入签名" style="width: 400px"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">账户：</label>
                <div class="layui-input-inline">
                    <input type="text" name="account" class="layui-input" placeholder="输入用户名" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码：</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" class="layui-input" placeholder="输入密码" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工资：</label>
                <div class="layui-input-inline">
                    <input type="text" name="wages" class="layui-input" placeholder="输入工资" style="width: 400px"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用：</label>
                <div class="layui-input-inline">
                    <input type="radio" name="enabled" value="1" title="yes">
                    <input type="radio" name="enabled" value="2" title="no" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属部门：</label>
                <div class="layui-input-inline">
                    <select class="layui-select" name="deptId" id="deptName">
                        <option value=""></option>
                    </select>
                </div>
            </div>


            <div class="layui-form-item" style="margin-top: 20px">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <!--确定取消-->
                    <div style="margin-bottom: 10px;margin-right: 10px">
                        <button type="button" lay-submit lay-filter="sub" class="layui-btn" style="width: 400px">确定添加</button>
                    </div>
                </div>
            </div>



        </div>
    </div>
    <input type="hidden" name="acatarUrl">
</form>
<div style="width: 100px;height: 500px;">

</div>


</body>
<!--获取ip和所在地-->
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script type="text/javascript">
    //console.log(returnCitySN["cip"]+','+returnCitySN["cname"])
</script>
<script>

    layui.use(['jquery','table','form','layer','laydate','upload'],function () {
        var $ = layui.$,
            table = layui.table,
            form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            upload = layui.upload;

        //获取当前时间
        var newTime;
        getTime();
        function getTime(){
            var myDate = new Date();
            var myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
            var myMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
            var myToday = myDate.getDate(); //获取当前日(1-31)
            var myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
            var myHour = myDate.getHours(); //获取当前小时数(0-23)
            var myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
            var mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
            newTime = myYear+'-'+myMonth+'-'+myToday+' '+myHour+':'+myMinute+':'+mySecond;
        };


        //渲染时间
        laydate.render({
            elem: '#date1'
        });

        //默认头像
        $('input[name=acatarUrl]').val('/images/moren.jpg');
        //上传头像
        var uploadInst = upload.render({
            elem: '#headPortrait'
            ,auto: true
            ,url: '/Upload/upload'
            ,field: 'file'
            ,choose:function(obj){
                var files = obj.pushFile();
                obj.preview(function(index,file,result){
                    $('#headPortrait').attr('src',result);
                })
            }
            ,done:function (res) {
                $('input[name=acatarUrl]').val(res.data);
            }
        });


        //获取部门数据
        $.ajax({
            url: '/jurisdiction/getZtree'
            ,data:{}
            ,dataType: 'json'
            ,success:function(data){
                var dept = data.data;

                for(var i=0; i<dept.length; i++){
                    $('#deptName').append('<option value="'+dept[i].id+'">'+dept[i].name+'</option>');
                }
                form.render();

            }
        });


        form.on('submit(sub)',function(obj){

            var user = obj.field;
            user.remark = '后台添加';
            user.registerDate = newTime;
            user.registerIp = returnCitySN["cip"];
            user.status = 1;
            $.ajax({
                 url: '/jurisdiction/addUser'
                ,data: user
                ,dataType: 'json'
                ,success:function(data){
                     if(data.data){
                         window,location = 'backstageStaff-list.html'
                         parent.quickEntry();
                         layer.msg('添加成功');
                     }
                }
            });


        });


        //返回
        backOff = function backOff() {
            var arr = localStorage.getItem("numArr");
            var numArr = arr.split(",");
            numArr.pop();
            window.parent.layui.element.tabChange('tab',numArr[numArr.length - 1]);
            localStorage.setItem("numArr",numArr);
        }
        //刷新
        refresh = function refresh(){
            window.location.reload();
        }

    })

</script>
</html>